<template>
	<view class="container">
		<view class="items">
			<view class="item" v-for="(item,index) in list.list" :key="item.id">

				<view class="cover" @click="goQrcode(item.id)">
					<image :src="item.demo_image" mode=""></image>
				</view>
				<text>{{item.name}}</text>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		list,
		getImage
	} from '../../api/index.js'
	export default {
		data() {
			return {
				list: [],
				code: ""
			}
		},
		onLoad(options) {
			this.code = options.code
		},
		onShow() {
			this.init()
		},
		methods: {
			init() {
				list({
					data: {
					}
				}).then(res => {
					if (res.code == 1) {
						console.log(res.data);
						this.list = res.data
						console.log(this.list);
					}
				})
			},
			goQrcode(val) {
				// 获取上一个页面的数据,
				// 获取当前开着的所有的页面对象,array,  item =>  所有的参数和方法
				uni.setStorage({
					key:"templateID",
					data: val,
						success: function () {
							console.log('success');
						}
					
				})
				var pages = getCurrentPages();
				// 获取数组的倒数第二个对象
				var prePage = pages[pages.length - 2];
				console.log("pages:", pages);
				console.log("prePage:", prePage);
				uni.showLoading({
					title: "加载中···"
				})
				getImage({
					data: {
						code: this.code,
						id: val
					}
				}).then(res => {
					if (res.code == 1) {
						console.log(val, 'valvalval');
						console.log(res.data);
						prePage.$vm.img = res.data.images;
						prePage.$vm.ID = val;
						uni.hideLoading()
						uni.navigateBack({})
					}
				})

				// 返回上一个页面		


				// // 修改上一个页面的值
				// console.log(val);
				// uni.redirectTo({
				// 	url: "signIn-qrcode?ID=" + val,
				// })
			}
		}

	}
</script>
<style lang="scss" scoped>
	.container {
		.items {
			display: flex;
			justify-content: space-around;
			flex-wrap: wrap;

			.item {
				text-align: center;
				margin: 12upx 0;

				text {
					margin-top: 12upx;
					width: 100%;
					background-color: #fff;
					font-size: 28upx;
				}

				.cover {
					width: 240upx;
					height: 240upx;

					image {
						width: 100%;
						height: 100%;
					}
				}

			}
		}

	}
</style>
